package demoCode;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.jupiter.api.Test;

import com.google.gson.Gson;

/**
 * @author jiangfeng on 2022/6/10
 */
public class TestSort {

    @Test
    public void test(){
        String json =
        "{\"orgLevelPrarentDepRelations\": [\n"
                + "{\n"
                + "\"orgLevel\": \"l4\",\n"
                + "\"depCodeList\": [\n"
                + "\"D0971\"\n"
                + "],\n"
                + "\"simpleDeps\": [\n"
                + "{\n"
                + "\"code\": \"D0971\",\n"
                + "\"name\": \"一级组织\",\n"
                + "\"nameEn\": \"UUUUUU\",\n"
                + "\"leaderUsername\": \"quwenqiang\",\n"
                + "\"hrbpUsername\": \"gaolei\"\n"
                + "}\n"
                + "]\n"
                + "},\n"
                + "{\n"
                + "\"orgLevel\": \"l5\",\n"
                + "\"depCodeList\": [\n"
                + "\"D2167\"\n"
                + "],\n"
                + "\"simpleDeps\": [\n"
                + "{\n"
                + "\"code\": \"D2167\",\n"
                + "\"name\": \"主数据2.0测试用勿动\",\n"
                + "\"nameEn\": \"zhe shi yi\",\n"
                + "\"leaderUsername\": \"quwenqiang\",\n"
                + "\"hrbpUsername\": \"gaolei\"\n"
                + "}\n"
                + "]\n"
                + "}\n"
                + "]}";

        Gson gson = new Gson();
        Depment d = gson.fromJson(json,Depment.class);

        List<OrgLevelDepRelation> orgLevelPrarentDepRelations = d.getOrgLevelPrarentDepRelations();
        System.out.println(gson.toJson(orgLevelPrarentDepRelations));
        List<OrgLevelDepRelation> collect = orgLevelPrarentDepRelations.stream()
                .sorted(Comparator.comparing((OrgLevelDepRelation e) -> DepOrgLevelEnum.sort(e.getOrgLevel()))
                        .reversed())
                .collect(Collectors.toList());
        System.out.println(gson.toJson(collect));
    }



}
